package com.cono.cvt

import com.cono.html.*
import com.cono.html.Structure
import com.cono.markup.*
import com.cono.html.Structure as HStructure
import com.cono.markup.Structure as MStructure


fun convertStructure(structure: MStructure): HStructure {
    return when (structure) {
        is Heading ->
            h1(structure.getData())

        is Paragraph ->
            p(structure.getData())

        is UnorderedList ->
            ul(structure.data.map { p(it) }.toTypedArray())

        is OrderList ->
            ol(structure.data.map { p(it) }.toTypedArray())

        is CodeBlock ->
            code(structure.getData())

        else ->
            p(structure.getData())
    }
}

fun main() {

    val doc = parse(
        arrayListOf(
            "- 1231231",
            "- asdadsas",
            "```java",
            "- asdads",
            "asdasdasd",
            "```",
            "* asdasdad"
        )
    )
    val cvt = doc.map { convertStructure(it) }.toList()

    val myhtml = html(
        "test", Structure(cvt.joinToString(""){it.data})
    )
    println(render(myhtml))
}